<template>
	<!-- 搜索 -->
	<view class="search-wrapper" :class="{'fixed':fixed,'pr-32':!filter}">
		<!-- 输入文字 -->
		<view class="search-box" v-if="!date">
			<image class="icon-search" src="@/static/contacts/icon_search.png" mode=""></image>
			<input style="width: 100%;" confirm-type="search" v-model="iptModel" @confirm="onSearch" type="text"
				class="fs-28" :placeholder="placeholder">
		</view>
		<!-- 选择月份 -->
		<view class="search-box  bg-white " style="justify-content: space-between;display: flex;align-items: center;"
			@click="onTiggleDate" v-else>
			<view class="label " style="color:#323233 ;">
				<text>{{iptDate}}</text>
			</view>
			<view class="value " style="display: flex;align-items: center;">
				<image class="cell-right-icon" src="@/static/mine/icon_right.png" mode=""></image>
			</view>
		</view>
		<view v-if="btn" class="btn-box">
			<u-button type="primary" text="搜索" @click="onSearch"></u-button>
		</view>
		<view v-if="filter" class="filter-box" @click="onFilter">
			<image style="width: 50rpx;height: 50rpx;" src="../static/mine/search_icon.png"></image>
		</view>

		<l-sel-date timeFormat="yyyy-mm" mode="year-month" :show.sync="showDate" :defaultValue="dataDefaultValue"
			@confirm="onConfirm">
		</l-sel-date>
	</view>
</template>

<script>
	import lSelDate from '@/components/l-filter/l-seldate.vue'
	export default {
		components: {
			lSelDate
		},
		props: {
			date: {
				default: false,
				type: Boolean
			},
			filter: {
				default: true,
				type: Boolean
			},
			placeholder: {
				default: '请输入',
				type: String
			},
			fixed: {
				default: true,
				type: Boolean
			},
			// 输入的内容
			iptData: {
				default: '',
				type: String
			},
			// 按钮
			btn: {
				default: false,
				type: Boolean
			},
			iptDate: {
				default: '',
				type: String
			},
		},
		data() {
			return {
				dataDefaultValue: '',
				iptModel: this.iptData,
				showDate: false,
				hide: false //无用
			}
		},
		watch: {
			time(val) {
				this.$emit('update:iptDate', val)
			},
			iptModel(val) {
				this.$emit('update:iptData', val)
			},
		},
		methods: {
			onConfirm(e) {
				this.showDate = false
				this.$emit('update:iptDate', e.date)
				this.$emit('onSearch', e.date)
			},
			onTiggleDate() {
				this.showDate = true
			},
			// 隐藏input 避免层级问题
			hideIpt() {
				this.hide = true
			},
			showIpt() {

				this.hide = false
			},
			// 点击键盘搜索按钮
			onSearch() {
				this.$emit('onSearch', '')
			},
			// 点击筛选图标
			onFilter(e) {
				this.$emit('onFilter')
			}
		}
	}
</script>
<style scoped lang="scss">
	.fixed {
		position: fixed;
		top: 0;
		left: 0;
		z-index: 9;
	}

	.search-wrapper {
		width: 100%;
		display: flex;
		align-items: center;
		padding: 20rpx 0 20rpx 32rpx;
		background-color: #F5F6FA;

		.search-box {
			flex: 1;
			width: 0;
			height: 64rpx;
			background: #FFFFFF;
			border-radius: 8rpx;
			color: $uni-text-color;
			display: flex;
			align-items: center;
			padding: 0 24rpx;

			.icon-search {
				width: 28rpx;
				height: 28rpx;
				margin-right: 16rpx;
			}
		}

		// .hide-input input {
		// 	opacity: 0;
		// }

		.filter-box {
			text-align: center;
			margin-left: 20rpx;
			padding-right: 32rpx;
			padding-left: 20rpx;
			position: relative;

			&::after {
				content: "";
				position: absolute;
				left: 0;
				height: 80%;
				top: 10%;
				background-color: #eaeaea;
				width: 2rpx;
			}
		}

		.btn-box {
			::v-deep button {
				height: 64rpx;
				font-size: 28rpx;
				margin-left: -4rpx;

				&::after {
					display: none;
				}
			}
		}
	}

	.pr-32 {
		padding-right: 32rpx !important;
	}
</style>
